home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 8.6 KB | 327 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Part.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWIDLE_H
- #include "FWIdle.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWODMISC_H
- #include "FWODMisc.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__SOUND__)
- #include <Sound.h>
- #endif
-
- //========================================================================================
- // Runtime information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfclock
- #endif
-
- //========================================================================================
- // Globals
- //========================================================================================
-
- //========================================================================================
- // Constants
- //========================================================================================
-
- const short kClockIdleFreq = 15;
-
- //========================================================================================
- // Class CClockPart
- //========================================================================================
-
- FW_DEFINE_AUTO(CClockPart)
-
- //----------------------------------------------------------------------------------------
- // CClockPart::CClockPart
- //----------------------------------------------------------------------------------------
- CClockPart::CClockPart(ODPart* odPart) :
- FW_CPart(odPart, FW_gInstance, kPartInfoID),
- fLastTime(FW_CTime::GetCurrentTime()),
- fClockContent(NULL),
- fLockIdle(FALSE),
- fIdler(NULL)
- #ifdef FW_BUILD_MAC
- ,fChimeSound(NULL),
- fTickSound(NULL)
- #endif
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::~CClockPart
- //----------------------------------------------------------------------------------------
- CClockPart::~CClockPart()
- {
- delete fIdler;
-
- #ifdef FW_BUILD_MAC
- if (fChimeSound)
- FW_CMemoryManager::FreeSystemHandle((FW_PlatformHandle)fChimeSound);
- fChimeSound = NULL;
-
- if (fTickSound)
- FW_CMemoryManager::FreeSystemHandle((FW_PlatformHandle)fTickSound);
- fTickSound = NULL;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CClockPart::Initialize(Environment* ev)
- {
- FW_CPart::Initialize(ev);
-
- // ----- Register Presentation -----
- fPresentation = RegisterPresentation(ev, "Apple:Presentation:ODFClock", TRUE);
-
- // ----- Initialize my menu -----
- // We instantiate a FW_CToggleItem from a stream so we must
- // keep it from being deadstripped.
- FW_DO_NOT_DEAD_STRIP(FW_CToggleItem);
- GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
-
- #ifdef FW_BUILD_MAC
- FW_CSharedLibraryResourceFile resFile(ev);
-
- // ----- Get default clock sounds
- fChimeSound = ::GetResource(soundListRsrc, kClockChime);
- ::DetachResource(fChimeSound);
-
- fTickSound = ::GetResource(soundListRsrc, kClockTick);
- ::DetachResource(fTickSound);
- #endif
-
- // ----- Create the Idler -----
- fIdler = FW_NEW(FW_CIdler, (this, kClockIdleFreq));
- fIdler->RegisterIdle(ev);
- }
-
- //------------------------------------------------------------------------------
- // CClockPart::NewPartContent
- //------------------------------------------------------------------------------
-
- FW_CContent* CClockPart::NewPartContent(Environment* ev)
- {
- fClockContent = FW_NEW(CClockContent, (ev, this));
- return fClockContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CClockPart::NewFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, FW_Boolean fromStorage)
- {
- FW_UNUSED(fromStorage);
-
- return FW_NEW(CClockFrame, (ev, odFrame, presentation, this, fClockContent));
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::DoIdle
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CClockPart::DoIdle(Environment* ev, const FW_CNullEvent& theNullEvent)
- {
- FW_UNUSED(theNullEvent);
-
- if (fLockIdle)
- return TRUE;
-
- FW_CTime currentTime = FW_CTime::GetCurrentTime();
- if (fLastTime != currentTime)
- {
- short frameCount = 0;
-
- // Update all the display frames of the same type
- FW_CPresentationFrameIterator iter(ev, fPresentation);
- for (CClockFrame *clockFrame = (CClockFrame*)iter.First(ev); iter.IsNotComplete(ev); clockFrame = (CClockFrame*)iter.Next(ev))
- {
- if ((!clockFrame->IsInLimbo(ev)))
- {
- frameCount++;
- if (clockFrame->GetViewType(ev) == FW_CPart::gViewAsFrameToken)
- clockFrame->UpdateClock(ev, currentTime);
- }
- }
-
- if (frameCount > 0)
- {
- if (fClockContent->HasTickSound())
- this->PlayTickSound();
- if (fClockContent->HasChimeSound() && (currentTime.GetMinute() == 0) && (currentTime.GetSecond() == 0))
- this->PlayChimeSound();
- }
-
- fLastTime = currentTime;
- }
- return TRUE;
- }
-
- //------------------------------------------------------------------------------
- // CClockPart::DoMenu
- //------------------------------------------------------------------------------
-
- FW_Boolean CClockPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_Boolean menuHandled = TRUE;
-
- switch (theMenuEvent.GetCommandID(ev))
- {
- case kODCommandAbout:
- ::FW_About(ev, this, kAbout);
- break;
- case cClockType:
- {
- fLockIdle = TRUE;
- fClockContent->SetClockType(fClockContent->GetClockType() == kAnalogClock ? kDigitalClock : kAnalogClock);
-
- fPresentation->ContentUpdated(ev);
-
- FW_CPresentationFrameIterator iter(ev, fPresentation);
- for (CClockFrame* frame = (CClockFrame*)iter.First(ev); iter.IsNotComplete(ev); frame = (CClockFrame*)iter.Next(ev))
- {
- frame->ChangeClockType(ev, fClockContent->GetClockType());
- }
- fLockIdle = FALSE;
- this->Changed(ev); // document has changed (enable Save menu item)
- }
- break;
-
- case cClockSoundsTick:
- fClockContent->ToggleTickSound();
- this->Changed(ev);
- break;
-
- case cClockSoundsChime:
- fClockContent->ToggleChimeSound();
- this->Changed(ev);
- break;
-
- default:
- menuHandled = FALSE;
- }
-
- return menuHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CClockPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- if (hasMenuFocus)
- {
- menuBar->EnableAndToggleCommand(ev, cClockType, TRUE, fClockContent->GetClockType() != kAnalogClock);
- menuBar->EnableAndCheckCommand(ev, cClockSoundsTick, TRUE, fClockContent->HasTickSound());
- menuBar->EnableAndCheckCommand(ev, cClockSoundsChime, TRUE, fClockContent->HasChimeSound());
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::PlayTickSound
- //----------------------------------------------------------------------------------------
-
- void CClockPart::PlayTickSound()
- {
- #ifdef FW_BUILD_MAC
- ::SndPlay(NULL, (SndListHandle)fTickSound, TRUE);
- #endif
- #ifdef FW_BUILD_WIN
- ::MessageBeep(-1);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::PlayChimeSound
- //----------------------------------------------------------------------------------------
-
- void CClockPart::PlayChimeSound()
- {
- #ifdef FW_BUILD_MAC
- ::SndPlay(NULL, (SndListHandle)fChimeSound, TRUE);
- #endif
- #ifdef FW_BUILD_WIN
- ::MessageBeep(-1);
- #endif
- }
-